package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDTO;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    //条件分页查询
    @GetMapping("/plan/search")
    @ApiOperation(value = "分页条件查询护理计划信息")
    public ResponseResult<PageResponse<NursingPlanVO>> selectByPage(
            @ApiParam(value = "护理计划名称") @RequestParam(required = false) String name,
            @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态") @RequestParam(required = false) Integer status){

        PageResponse<NursingPlanVO> page = nursingPlanService.selectByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(page);
    }

    //查询所有护理计划
    @GetMapping("/plan")
    @ApiOperation(value = "查询所有护理计划信息")
    public ResponseResult<List<NursingPlanVO>> selectAll() {
        List<NursingPlanVO> all = nursingPlanService.selectAll();
        return ResponseResult.success(all);
    }

    //根据id查询
    @GetMapping("/plan/{id}")
    @ApiOperation(value = "根据id查询护理计划信息")
    public ResponseResult<NursingPlanVO> getNursingPlanById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id) {
        return ResponseResult.success(nursingPlanService.selectById(id));
    }

    //删除护理计划
    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划信息")
    public ResponseResult removeNursingPlan(@ApiParam(value = "护理计划id") @PathVariable Long id) {
        nursingPlanService.removeNursingPlan(id);
        return ResponseResult.success();
    }

    //启用/禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理计划信息")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理计划id") @PathVariable Long id,
            @ApiParam(value = "护理计划状态") @PathVariable Integer status) {
        nursingPlanService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

    //添加护理计划
    @PostMapping("/plan")
    @ApiOperation(value = "添加护理计划信息")
    public ResponseResult addNursingPlan(
            @ApiParam(value = "护理计划信息", required = true)
            @RequestBody NursingPlanDTO nursingPlanDTO) {
        nursingPlanService.addNursingPlan(nursingPlanDTO);
        return ResponseResult.success();
    }

    //修改护理计划
    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划信息")
    public ResponseResult updateNursingPlan(
            @ApiParam(value = "护理计划id") @PathVariable Long id,
            @ApiParam(value = "护理计划信息", required = true)
            @RequestBody NursingPlanDTO nursingPlan) {
        nursingPlanService.updateNursingPlan(nursingPlan);
        return ResponseResult.success();
    }
}
